import Vue from 'vue'
import VueRouter from 'vue-router'
const Home = () => import(/* webpackChunkName: "home" */ '../components/Home.vue')
const News = () => import(/* webpackChunkName: "home" */ '../components/HomeNews.vue')
const Message = () => import(/* webpackChunkName: "home" */ '../components/HomeMessage.vue')

const About = () => import(/* webpackChunkName: "home" */ '../components/About.vue')
const User = () => import(/* webpackChunkName: "home" */ '../components/User.vue')
const Profile = () => import(/* webpackChunkName: "home" */ '../components/Profile.vue')
const Advanced = () => import(/* webpackChunkName: "home" */ '../view/advanced/advanced.vue')
const KonvaDemo = () => import(/* webpackChunkName: "home" */ '../view/konva/konva.vue')
const StudyPage = () => import(/* webpackChunkName: "home" */ '../view/study/study.vue')

Vue.use(VueRouter)


const routes = [

    {
        path: "/",
        redirect: "/home",
    },
    {
        path: '/Advanced',
        name: 'advanced',
        component: Advanced,
        meta: {
            title: "登录"
        }
    },
    {
        path: '/KonvaDemo',
        name: 'konvademo',
        component: KonvaDemo,
        meta: {
            title: "demo"
        }
    },
    {
        path: '/StudyPage',
        name: 'studypage',
        component: StudyPage,
        meta: {
            title: "study"
        }
    },
    {
        path: '/home',
        name: 'home',
        component: Home,
        meta: {
            title: "首页"
        },
        children: [
            {
                path: '/',
                redirect: 'news'

            },
            {
                path: 'news',
                component: News
            },
            {
                path: 'message',
                component: Message
            }
        ]
    },
    {
        path: '/about',
        name: 'about',
        component: About,
        meta: {
            title: "关于"
        }

    },
    {
        path: "/user/:user",
        component: User,
        meta: {
            title: "用户"
        }

    },
    {
        path: "/profile",
        component: Profile,
        meta: {
            title: "个人中心"
        }

    },

]

const router = new VueRouter({
    routes,
    mode: 'history'
})
router.beforeEach((to, from, next) => {
    console.log(to);

    document.title = to.matched[0].meta.title

    next()
})
export default router